const jwt = require('jsonwebtoken')
const { getPrivateKey } = require('./rsaControl')
const { tokenExpireTime } = require('../config')
const { token } = require('morgan')

const sendToken = async (value) => {
  console.log('value: ', typeof value, value)
  let privateKey = await getPrivateKey()
  try {
    const token = await jwt.sign(value, privateKey, { algorithm: 'RS256', expiresIn: tokenExpireTime })
    return token
  } catch (error) {
    console.log('error: ', error)
  }
}
module.exports = sendToken
